// pages/storeDetails/storeDetails.js
var app = getApp();
var req = require("../../utils/req.js");
var url = require("../../utils/url.js");
Page({

  /**
   * 页面的初始数据
   */
  data: {
    proTabs: ['电话', '微信'],
    activeIndex: 0,
    storeId: '',
    storeInfo: '',
    location: {},
    phone:'',
    storeInfoList:[]
  },
  onLoad: function(e) {
    this.setData({
      storeId: e.sotreId
    })
    this.getStoreDetails();
  },
  tabClick: function(e) {
    this.setData({
      sliderOffset: e.currentTarget.offsetLeft,
      activeIndex: e.currentTarget.id,
    });
  },
  getStoreDetails: function() {
    var that = this
    const data = {
      storeId: that.data.storeId
    }
    req.userRequest("请稍等", 'POST',url.user['userGetStoreInfo'], data, function back(res) {
      that.setData({
        storeInfo: res.data,
        phone:res.data.phone,
        storeInfoList:res.data.storeInfoList
      })
      that.data.location = {
        latitude: res.data["latitude"],
        longitude: res.data["longitude"]
      }
      console.log(res)
    })
  },
  /**
   * 页面的初始数据
   */
  checkMap: function() {
    var that=this;
    wx.openLocation({
      latitude: that.data.location["latitude"],
      longitude: that.data.location["longitude"],
      scale: 18,
      success: function (res) {
        console.log(res)
      },
      fail: function (res) {
        console.log(res)
      }
    })
  },
  callPhone:function(){
    wx.makePhoneCall({
      phoneNumber:this.data.phone,
      success:function(){
        console.log('拨打成功')
      },
      fail:function(){
        console.log('拨打失败')
      }
    })
  }

})